package com.wk1un2.controller;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wk1un2.service.ComputersService;
import com.wk1un2.util.Result;

@RestController
public class ComputersController {
	@Autowired
	private ComputersService computersservice;

	@RequestMapping("/getAllComputers")
	public Object getAll(@RequestParam Map<String, Object> map) {
		Integer page = Integer.parseInt(map.get("page").toString());
		Integer limit = Integer.parseInt(map.get("limit").toString());
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		Result res = new Result(0, "", computersservice.count(map), computersservice.getAll(map));
		return res;
	}

	@RequestMapping("/addComputers")
	public Object add(@RequestParam Map<String, Object> map) {
		map.put("c_no", new Date().getTime());
		Result res = new Result(0, "", computersservice.add(map), true);
		return res;
	}

	@RequestMapping("/updateComputers")
	public Object update(@RequestParam Map<String, Object> map) {
		map.put("c_no", new Date().getTime());
		Result res = new Result(0, "", computersservice.update(map), true);
		return res;
	}

	@RequestMapping("/deleteComputers")
	public Object delete(Integer c_id) {
		Result res = new Result(0, "", computersservice.delete(c_id), true);
		return res;
	}
}
